/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package co.com.going.persistencia;

import co.com.going.modelo.Nota;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.Query;

/**
 *
 * @author Olguita
 */
@Stateless
public class DAOnota implements IDAOnota {

    @PersistenceContext
    private EntityManager entityManager;
    
    @Override
    public void crearNota(Nota nota) {
        
           try {
            
            entityManager.persist(nota);
            
        } catch (Exception e) {
            throw e;
            
        }
    }

    @Override
    public void eliminarNota(Nota nota) {
        
         try {
            
            entityManager.remove(nota);
            
        } catch (RuntimeException e) {
        
             throw e;
            
        }
    }

    @Override
    public void modificarNota(Nota nota) {
        
        try {
            
            entityManager.merge(nota);
            
        } catch (RuntimeException e) {
            
           throw e;
            
        }
    }

    @Override
    public List<Nota> notas() {
        
         try {
            
            String Jpql="select c from Nota c";
            Query query=entityManager.createQuery(Jpql);
            return query.getResultList();
            
            
        } catch (RuntimeException e) {
            
            throw e;
        }
    }

   
    @Override
    public Nota buscarNotaporId(Integer  IdNota) {
        
         try {
            
            return entityManager.find(Nota.class, IdNota);
            
            
        } catch (RuntimeException e) {
            
            throw e;
        }
    }
}
